package com.shg.web.action;

import java.io.InputStream;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;

@Controller
public class FileDownAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String inputPath;

	private String message;
	
	private String fileName;
	
	public void setInputPath(String inputPath) {
		this.inputPath = inputPath;
	}
	
	public InputStream getTargetFile(){
		try{
			fileName=inputPath.substring(inputPath.lastIndexOf("/")+1);
			return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
		}catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public String execute() {
		try{
			return SUCCESS;
		}catch (Exception e) {
			e.printStackTrace();
		}
		return ERROR;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

}
